﻿using Akka.Actor;
using Akka.Routing;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dapper.Sharding.CAP
{
    public class ClientCap
    {
        private readonly ActorSystem actorSystem;

        private readonly IActorRef actor;

        internal ConcurrentDictionary<string, DistributedTransactionCap> dict = new ConcurrentDictionary<string, DistributedTransactionCap>();

        public ClientCap(ActorSystem actorSystem, string actorName, int pool = 100)
        {
            this.actorSystem = actorSystem;
            var props = Props.Create<ClientActor>(this).WithRouter(new RoundRobinPool(pool));
            actor = this.actorSystem.ActorOf(props, actorName);
        }

        internal void Tell(string serverActor, TranMessage msg)
        {
            actorSystem.ActorSelection(serverActor).Tell(msg, actor);
        }
    }
}
